home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9860 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John Noland)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Do you see what is wrong?
  5. Date: 14 Mar 1996 00:16:30 GMT
  6. Organization: Prose Software
  7. Message-ID: <4i7ogu$ij@newshost.cyberramp.net>
  8. References: <4i72h6$2d4@blaze.cs.jhu.edu>
  9. NNTP-Posting-Host: ramp2-1.cyberramp.net
  10. X-Newsreader: WinVN 0.99.5
  11.  
  12. In article <4i72h6$2d4@blaze.cs.jhu.edu>, lasher@hops.cs.jhu.edu says...
  13.  
  14. >int             j = -1, n, i, distance, nextCoord, current = 0, status[SIZE];
  15.                  ^^^^^^
  16.                  This is going to be the value of j on the first iteration
  17.                  of your for loop below.
  18. >for( n = 0; n < SIZE; n++, j++ ) {
  19.  
  20. Initialize j to zero, either here or above in your declaration.
  21. for (n = 0, j = 0; n < SIZE; n++. j++) {
  22. The way it is now you're going to try and access the -1 element of
  23. your array. This isn't a good thing to do!!
  24. I also don't see why you're using n AND j, superficially it looks like
  25. they should be the same values. Are you trying to have n access one element
  26. ahead of j? If you are, you need to make an explicit check below, so that
  27. you don't try and access an invalid array element (Namely the dreaded -1).
  28.  
  29. >        if( scanf("%f%f", &xtemp, &ytemp) != EOF) 
  30. >                {
  31. >                Xposition[n] = xtemp;
  32. >                Yposition[n] = ytemp; 
  33. >                }
  34. >        else    {
  35. >                printf("Done entering Numbers");  
  36. >                n = SIZE; 
  37. >                printf("\n%f %f", Xposition[j], Yposition[j]);
  38. >                }  /*  <== I get a core dump right here. _after_ executing the 
  39. >stuff in the else statemnet */ 
  40. >        } 
  41. >}
  42.  
  43.